package com.sirui.jpa.utils;

import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.List;

@Data
@NoArgsConstructor
public class ParamBean {
    private String fieldName;
    private List<Object> fieldValues = new ArrayList<>();
    private SpecificationUtils.CompareType compareType;
    private SpecificationUtils.RelationType relationType;
    private List<ParamBean> list = new ArrayList<>();

    public ParamBean(String fieldName, List<Object> fieldValues, SpecificationUtils.CompareType compareType, SpecificationUtils.RelationType relationType) {
        this.fieldName = fieldName;
        this.fieldValues = fieldValues;
        this.compareType = compareType;
        this.relationType = relationType;
    }

    public List<ParamBean> build() {
        return list;
    }

    public ParamBean add(String fieldName, SpecificationUtils.CompareType compareType) {
        list.add(new ParamBean(fieldName, new ArrayList<>(), compareType, SpecificationUtils.RelationType.AND));
        return this;
    }

    public ParamBean add(String fieldName, SpecificationUtils.CompareType compareType, SpecificationUtils.RelationType relationType) {
        list.add(new ParamBean(fieldName, new ArrayList<>(), compareType, relationType));
        return this;
    }

    public ParamBean add(String fieldName, List<Object> fieldValues, SpecificationUtils.CompareType compareType, SpecificationUtils.RelationType relationType) {
        list.add(new ParamBean(fieldName, fieldValues, compareType, relationType));
        return this;
    }
}
